package com.caigou.service.impl;

import com.caigou.bean.cms.entity.ArticleTitle;
import com.caigou.mapper.cms.ArticleTitleMapper;
import com.caigou.pojo.ArticleDataTitleListData;
import com.caigou.pojo.ArticleTitleData;
import com.caigou.service.ArticleTitleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("articleTitleService")
@Slf4j
public class ArticleTitleServiceImpl implements ArticleTitleService {

    @Resource
    private ArticleTitleMapper articleTitleMapper;

    @Override
    public ArticleTitle saveArticleTitleData(String articleId, Integer articleTitleType, String articleTitle, Integer articleImageId,
                                             String articleImage, String articleImageAlt) {
        ArticleTitle articleTitleEntity = new ArticleTitle();
        articleTitleEntity.setArticleId(articleId);
        articleTitleEntity.setArticleTitleType(articleTitleType);
        articleTitleEntity.setArticleTitle(articleTitle);
        articleTitleEntity.setArticleImageId(articleImageId);
        articleTitleEntity.setArticleImage(articleImage);
        articleTitleEntity.setArticleImageAlt(articleImageAlt);
        articleTitleMapper.saveArticleTitleData(articleTitleEntity);
        return articleTitleEntity;
    }

    @Override
    public int loadArticleTitleExist(String articleId, Integer articleTitleType) {
        return articleTitleMapper.loadArticleTitleExist(articleId,articleTitleType);
    }

    @Override
    public int deleteArticleTitle(Integer id) {
        return articleTitleMapper.deleteArticleTitle(id);
    }


    @Override
    public List<ArticleTitleData> loadArticleTitleList(String articleId) {
        return articleTitleMapper.loadArticleTitleList(articleId);
    }

    @Override
    public int updateArticleTitleData(Integer id, Integer articleTitleType, String articleTitle, Integer articleImageId,
                                      String articleImage, String articleImageAlt) {
        ArticleTitle record = new ArticleTitle();
        record.setId(id);
        record.setArticleTitleType(articleTitleType);
        record.setArticleTitle(articleTitle);
        record.setArticleImageId(articleImageId);
        record.setArticleImage(articleImage);
        record.setArticleImageAlt(articleImageAlt);
        return articleTitleMapper.updateArticleTitleData(record);
    }


    @Override
    public ArticleTitle loadArticleTitle(String articleId, Integer titleType) {
        return articleTitleMapper.loadArticleTitle(articleId,titleType);
    }

    @Override
    public int deleteArticleTitleByArticleId(String articleId){
        return articleTitleMapper.deleteArticleTitleByArticleId(articleId);
    }

    @Override
    public int loadArticleTitleReleaseStatus(String articleId, Integer articleTitleType) {
        return articleTitleMapper.loadArticleTitleReleaseStatus(articleId,articleTitleType);
    }
}
